<?php

namespace Library;

use \Org\Util\EasyWechat;

class Wx 
{
    private static $_instance;

    private function __construct() {
    }
    
    public function __clone() {
        trigger_error('Clone is not allow!', E_USER_ERROR);
    }
    
    public static function getInstance() {
        $options = array(
            'token'=> C('WX_TOKEN'), //填写你设定的key
            'appid'=> C('WX_APPID'), //填写高级调用功能的app id, 请在微信开发模式后台查询
            'appsecret'=> C('WX_APPSERCRET'), //填写高级调用功能的密钥
            'encodingaeskey'=> C('WX_ENCODINGAESKEY'), //
            'logfile' => SITE_PATH.'/data/runtime/Logs/weixin/weixin.log',//
            'debug' => true,
        );
        
        if (!(self::$_instance instanceof EasyWechat)) {
            self::$_instance = new EasyWechat($options);
        }

        return self::$_instance;
    }
    
    public static function __callStatic($method, $arguments) {
        $wx = self::getInstance();
        $reuslt = call_user_func_array(array($wx, $method), $arguments);
        if ($reuslt == FALSE) {
            if ($wx->errCode == 40001) {
                $wx->resetAuth();
                $reuslt = call_user_func_array(array($wx, $method), $arguments);
            }
        }
        return $reuslt;
    }

    public static function getLastErrCode() {
        $wx = self::getInstance();
        return $wx->errCode;
    }
}





